package com.ambow.shop.action.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ambow.shop.action.Action;
import com.ambow.shop.domain.Product;
import com.ambow.shop.service.ProductService;
import com.ambow.shop.service.impl.ProductServiceImpl;
import com.ambow.shop.util.DataValidator;
import com.ambow.shop.util.Page;

public class ListProductAction implements Action {
	private ProductService productService = new ProductServiceImpl();

	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) {
		String page = request.getParameter("page");
		int currentPage = (page != null && DataValidator.isInteger(page)) ? currentPage = Integer.parseInt(page) : 1;
		int pageSize = 3;
		Page<Product> data = productService.findProducts(currentPage, pageSize);
		request.setAttribute("data", data);
		return "../view/productList.jsp";
	}

}
